<?php

include dirname(dirname(dirname(__FILE__))) . '/include/common.php';

class webServiceInviteFriendFacebook extends core {

    public function process() {
        $user_id = intval($_POST['user_id']);
        $arr_friend_list = $_POST['friend_list'];
        $friend_list = '';
        foreach ($arr_friend_list as $friend_id) {
            $friend_id = $this->db->escape($friend_id);
        }
        $friend_list = implode(",", $arr_friend_list);
        $result = $this->db->query("UPDATE `guests` SET 
                                            `is_invite` = 1                                           
                                        WHERE user_id = '{$user_id}' AND guest_id IN ($friend_list)");

        if ($result >= 0) {
            if(count($arr_friend_list)==1){
            $this->_JSONResponse(array('error' => 0, 'msg' => 'A contact has been added'));
            }else{
                $this->_JSONResponse(array('error' => 0, 'msg' => 'Contacts have been added'));
            }
        } else {
            $this->_JSONResponse(array('error' => 1, 'msg' => 'Oops, something went wrong. Please try again.'));
        }
    }

}

$processor = new webServiceInviteFriendFacebook();
$processor->process();
?>